package com.xuedongzhilian.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuedongzhilian.dto.UserInfoExtendDTO;
import com.xuedongzhilian.entity.UserInfoExtend;
import com.xuedongzhilian.mapper.UserInfoExtendMapper;
import com.xuedongzhilian.service.IUserInfoExtendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户扩展信息服务实现类
 * </p>
 *
 * @author 学动智联团队
 * @since 2025-10-14
 */
@Service
public class UserInfoExtendServiceImpl extends ServiceImpl<UserInfoExtendMapper, UserInfoExtend> implements IUserInfoExtendService {

    @Resource
    private UserInfoExtendMapper userInfoExtendMapper;

    @Override
    public UserInfoExtendDTO getUserInfoExtend(Long userId) {
        UserInfoExtend userInfoExtend = userInfoExtendMapper.selectById(userId);
        if (userInfoExtend == null) {
            return null;
        }
        return BeanUtil.copyProperties(userInfoExtend, UserInfoExtendDTO.class);
    }

    @Override
    public boolean updateUserInfoExtend(UserInfoExtendDTO userInfoExtendDTO) {
        UserInfoExtend userInfoExtend = BeanUtil.copyProperties(userInfoExtendDTO, UserInfoExtend.class);
        return userInfoExtendMapper.updateById(userInfoExtend) > 0;
    }

    @Override
    public boolean initUserInfoExtend(Long userId) {
        UserInfoExtend userInfoExtend = new UserInfoExtend();
        userInfoExtend.setUserId(userId);
        return userInfoExtendMapper.insert(userInfoExtend) > 0;
    }
}